<template>
	<!-- 我的-账户 -->
	<view class="account public">
		<view class="main">
			<!-- 总资产 -->
			<view class="header">
				<view class="header-left">
					<view class="header-title">
						总资产
					</view>
					<view class="header-price">
						{{totalAssets | filterPrice}}
					</view>
				</view>
				<view class="header-right" @click="JumpWalletWithdrawal">
					提现
				</view>
			</view>
			<!-- 账单明细 -->
			<view class="BillDetails">
				<view class="BillDetails-title">
					<view class="BillDetails-title-left">
						账单明细
					</view>
					<view class="BillDetails-title-center">
						<view class="">
							<picker mode="date" @change="startDates">
								<view class="picker-main">
									<view class="">
										<image src="" mode=""></image>
									</view>
									<view class="">
										<!-- 开始日期 -->
										{{startDate}}
									</view>
								</view>
							</picker>
						</view>
						<view class="to">
							至
						</view>
						<view class="">
							<picker mode="date" end="startDate" @change="endDates">
								<view class="picker-main">
									<view class="">
										<image src="" mode=""></image>
									</view>
									<view class="">
										<!-- 结束日期 -->
										{{endDate}}
									</view>
								</view>
							</picker>
						</view>
					</view>
					<view class="BillDetails-title-right" @click="eventScreen">
						筛选
					</view>
				</view>
				<view class="BillDetails-main">
					<view class="BillDetails-main-item" v-for="item in BillDetailsArr" :key="item.id">
						<view class="numPrice" v-if="item.num">
							{{item.num}}
						</view>
						<view class="numPrice" v-else>
							<text>￥</text>{{item.price}}
						</view>
						<view class="">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
			<!-- 记录 -->
			<view class="record">
				<view class="record-main">
					<view class="record-main-item" v-for="item in recordArr" :key="item.id">
						<view class="record-main-item-left">
							<view class="">
								{{item.type_name}}
							</view>
							<view class="">
								{{item.type_tag}}
							</view>
						</view>
						<view class="record-main-item-right">
							<view :class="item.account_data == 0 ? 'priceExpenditure' : 'priceIncome'">
								<text>{{item.account_data}}</text>
							</view>
							<view class="">
								<text>{{item.create_time | formatTime}}</text>
							</view>
						</view>
					</view>
					<u-loadmore :status="status" v-if="recordArr.length == 0" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const $api = require('@/utils/request.js').API
	export default {
		data() {
			return {
				// totalAssets: 1486, // 总资产
				totalAssets: 0, // 总资产
				startDate: '开始日期',	// 开始日期
				endDate: '结束日期',	// 结束日期
				BillDetailsArr: [
					{
						id:1,
						num:0,
						price:0,
						title: '完成订单'
					},
					{
						id:2,
						// num: '',
						price:0,
						title: '已到账'
					},
					{
						id:3,
						// num: '',
						// price:20,
						price:0,
						title: '待到账'
					},
					{
						id:4,
						// num: '',
						price:0,
						title: '支出'
					},
				],
				recordArr:[],
				page: 1,
				page_count: 0,
				status: 'loading',
			}
		},
		onLoad() {
			this.accountInformation()
			this.accountDetails()
			this.userInformation()
		},
		onReachBottom() {
			if(this.page >= this.page_count) {
				this.status = 'nomore'
			} else {
				this.page = this.page + 1
				this.accountDetails()
			}
		},
		methods: {
			// 账户信息
			accountInformation(){
				$api.postAccountInformation({
					// account_type: 'point'
				}).then(res => {
					this.totalAssets = res.data.data.balance_money
				})
			},
			userInformation(){
				$api.postUserInformation({}).then(res => {})
			},
			// 账户明细
			accountDetails(start_time,end_time){
				$api.postAccountDetails({
					status: 'all',
					page: this.page,
					start_time: start_time,
					end_time: end_time,
				}).then(res => {
					// console.log(res,'账户明细');
					this.count = res.data.data.count
					this.page_count = res.data.data.page_count
					this.recordArr = [...this.recordArr,...res.data.data.list]
				})
			},
			eventScreen(){
				this.accountDetails(this.startDate,this.endDate)
				this.recordArr = []
			},
			// 开始日期
			startDates(e){
				this.startDate = e.detail.value
			},
			// 结束日期
			endDates(e){
				if(e.detail.value < this.startDate) {
					uni.showToast({
						title:"结束时间不能小于开始时间",
						icon:"none",
						duration:2000
					})
				} else {
					this.endDate = e.detail.value
				}
			},
			// 提现
			JumpWalletWithdrawal(){
				uni.navigateTo({
					// url:'../../pages/my/WalletWithdrawal'
					url:'../my/WalletWithdrawal'
				})
			}
		},
		filters: {
			filterPrice(e) {
				return Number(e).toFixed(2)
			}
		}
	}
</script>

<style lang="less" scoped>
	.account {
		background: #F7F7F7;

		.main {
			background: white;
		}

		// 总资产
		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// width: 750rpx;
			height: 245rpx;
			border-bottom: 1px solid #F7F7F7;
			padding: 0 64rpx 0 35rpx;

			.header-left {
				.header-title {
					font-size: 26rpx;
					font-weight: 500;
					color: #424242;
				}

				.header-price {
					font-size: 76rpx;
					font-weight: 400;
					color: #F14500;
					padding-top: 20rpx;
				}
			}

			.header-right {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 165rpx;
				height: 64rpx;
				background: #F14500;
				border-radius: 32rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		// 账单明细
		.BillDetails {
			padding-top: 20rpx;
			padding-bottom: 30rpx;
			border-bottom: 1px solid #F7F7F7;
			.BillDetails-title {
				display: flex;
				justify-content: space-between;
				padding: 0 28rpx 0 29rpx;
				.BillDetails-title-left {
					font-size: 28rpx;
					font-weight: 500;
					color: #000000;
				}
				.BillDetails-title-center {
					display: flex;
					align-items: center;
					.to {
						font-size: 24rpx;
						font-weight: 400;
						color: #333333;
						padding: 0 20rpx;
					}
					.picker-main {
						display: flex;
						align-items: center;
						// width: 166rpx;
						// width: 136rpx;
						height: 50rpx;
						border: 1px solid #333333;
						border-radius: 6rpx;
						padding: 0 15rpx;
						image {
							width: 22rpx;
							height: 22rpx;
						}
						view:last-child {
							font-size: 24rpx;
							font-weight: 400;
							color: #333333;
							padding-left: 10rpx;
						}
					}
				}
				.BillDetails-title-right {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 100rpx;
					height: 50rpx;
					background: #F14500;
					border-radius: 6rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
			.BillDetails-main {
				display: flex;
				justify-content: space-around;
				align-items: center;
				text-align: center;
				padding-top: 50rpx;
				.BillDetails-main-item {
					font-size: 28rpx;
					font-weight: 400;
					color: #444343;
					.numPrice {
						color: #000000;
					}
				}
			}
		}
		// 记录
		.record {
			.record-main {
				.record-main-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					height: 119rpx;
					border-bottom: 1px solid #F7F7F7;
					padding: 0 60rpx 0 50rpx;
					.record-main-item-left {
						view:first-child {
							font-size: 28rpx;
							font-weight: 400;
							color: #333333;
						}
						view:last-child {
							font-size: 24rpx;
							font-weight: 400;
							color: #808080;
							padding-top: 10rpx;
						}
					}
					.record-main-item-right {
						text-align: right;
						.priceIncome {
							font-size: 38rpx;
							font-weight: 400;
							color: #F14500;
						}
						.priceExpenditure {
							font-size: 38rpx;
							font-weight: 400;
							color: #FF9C44;
						}
						view:last-child {
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #808080;
							line-height: 40rpx;
							text:last-child {
								padding-left: 20rpx;
							}
						}
					}
				}
			}
		}
	}
</style>